<template>
  <div>
    <div v-for="(item, index) in imgArr" :key="index" class="card">
      <image lazy-load class="width100" :src="item" mode="widthFix"  />
    </div>
    <div class="btn-full-box">
      <div :class="['btn-full', btnDisabled ? 'disabled' : '']" @tap="hardMake">{{btnText}}</div>
    </div>
  </div>
</template>

<script>
import getPuerperaBookingImg from '@/interface/picture/getPuerperaBookingImg'
import getChildKnowledge from '@/interface/getChildKnowledge'
import {serviceInfo} from '@/config'

export default {
  components: { },
  data () {
    return {
      btnDisabled: false,
      knowledgeId: '',
      orderPrice: '',
      img: '',
      btnText: '',
      imgObj: {
        kr: {
          bizType: 'breas_opening_image',
          id: '1108667300351991808'
        },
        cr: {
          bizType: 'lactation_image',
          id: '1108667300351991808'
        },
        myh: {
          bizType: 'full_moon_sweat_image',
          id: '1108667300351991808'
        },
        chxf: {
          bizType: 'postpartum_repair_image',
          id: '1108667300351991808'
        },
        yezs: {
          bizType: 'parenting_knowledge_image',
          id: '1108667300351991808'
        },
        myz: {
          bizType: 'full_moon_illumination_image',
          id: '1108667300351991808'
        }
      },
      imgArr: []
    }
  },
  methods: {
    hardMake () {
      if(this.btnDisabled){
        return;
      }
      if(this.checkLogin()){ // 如果未登录会自动跳转
        const query = this.$root.$mp.query
        let url = `/pages/puerperaBooking/${query.type}/main`
        if (query.type === 'yezs') {
          url = url + `?knowledgeId=${this.knowledgeId}&orderPrice=${this.orderPrice}`
        }
        uni.navigateTo({ url })
      }
    },
    getChildKnowledge(){
      this.btnDisabled = true
      getChildKnowledge().then(data => {
        const alreadyNum = data.alreadyNum || 0
        if(alreadyNum < data.peopleNum){
          this.btnDisabled = false
          this.knowledgeId = data.id
          this.orderPrice = data.itemPrice
        }else{
          this.dialog.showToast('报名人数已满')
        }
      })
    },
    setTitle(type){
      const name = serviceInfo[type].name;
      uni.setNavigationBarTitle({
        title: name
      })
      // #ifdef  H5
			document.title = name
			// #endif
    }
  },
  mounted () {
    const type = this.$root.$mp.query.type
    this.setTitle(type)
    getPuerperaBookingImg(this.imgObj[type]).then(list => {
      this.imgArr = list
    })
    if (type === 'yezs') {
      this.btnText = '立即报名'
      this.getChildKnowledge()
    } else {
      this.btnText = '立即预约'
    }

  }
}
</script>
<style lang="less">
  .card{
    margin-bottom: 30upx;
    .width100 {
      height: auto;
    }
  }
</style>